package com.telit.firecommand.service.impl;

import com.telit.firecommand.dao.CommAlarmPromptJobDao;
import com.telit.firecommand.entity.CommAlarmPromptJob;
import com.telit.firecommand.service.JobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


/**
 * Create by Chencf 2022/10/27
 */
@Service
@Slf4j
public class JobServiceImpl implements JobService {

    @Autowired
    private CommAlarmPromptJobDao commAlarmPromptJobDao;


    @Override
    public void reviseData() {
        //先删除表数据
        commAlarmPromptJobDao.deleteAll();
        //查询所有的需要提示的火情id
        List<CommAlarmPromptJob> commAlarmPromptJobList = commAlarmPromptJobDao.selectAllPromptFire();
        //补全数据
        commAlarmPromptJobList.forEach(commAlarmPromptJob -> commAlarmPromptJob.setCreateTime(new Date()));

        for (CommAlarmPromptJob entity:commAlarmPromptJobList){
            commAlarmPromptJobDao.insert(entity);
        }
    }

    @Override
    public void alarm(String fireId) {
        commAlarmPromptJobDao.alarm(fireId);
    }

    @Override
    public void insertTask(String fireId, String districtCode,Date startTime) {
        CommAlarmPromptJob commAlarmPromptJob = new CommAlarmPromptJob();
        commAlarmPromptJob.setFireId(fireId);
        commAlarmPromptJob.setStatus(1);
        commAlarmPromptJob.setDistrictCode(districtCode);
        commAlarmPromptJob.setCreateTime(new Date());
        commAlarmPromptJob.setAlarmTime(startTime);
        commAlarmPromptJob.setShiIsRemind(0);
        commAlarmPromptJob.setShenIsRemind(0);
        commAlarmPromptJobDao.insertSelective(commAlarmPromptJob);
    }
}
